package com.ta.gulimall.coupon.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ta.gulimall.common.view.to.SkuFullReductionTo;
import com.ta.gulimall.coupon.service.MemberPriceService;
import com.ta.gulimall.coupon.service.SkuLadderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ta.gulimall.coupon.dao.SkuFullReductionDao;
import com.ta.gulimall.coupon.entity.SkuFullReductionEntity;
import com.ta.gulimall.coupon.service.SkuFullReductionService;

import java.math.BigDecimal;


@Service("skuFullReductionService")
public class SkuFullReductionServiceImpl extends ServiceImpl<SkuFullReductionDao, SkuFullReductionEntity> implements SkuFullReductionService {

    @Autowired
    SkuLadderService skuLadderService;
    @Autowired
    MemberPriceService memberPriceService;
    @Override
    public void saveSkuFullReduction(SkuFullReductionTo skuFullReductionTo) {
        SkuFullReductionEntity skuFullReduction = BeanUtil.copyProperties(skuFullReductionTo, SkuFullReductionEntity.class);
        skuFullReduction.setAddOther(skuFullReductionTo.getPriceStatus());

        if(skuFullReduction.getFullPrice().compareTo(new BigDecimal(0)) > 0){
            this.save(skuFullReduction);
        }

        skuLadderService.saveSkuLadder(skuFullReductionTo);

        memberPriceService.saveMemberPrices(skuFullReductionTo);
    }

}